package sh.grapendaal.tsuushin.module.uno.engine;

import java.util.ArrayList;
import java.util.List;

/**
 * A player in the Uno game.
 */
public class Player {

	/**
	 * The nickname of the player.
	 */
	private String nickname;

	/**
	 * The cards this player holds.
	 */
	private List<Card> cards = new ArrayList<Card>();

	/**
	 * Constructs a new player with the given nickname. The nickname is used as
	 * a unique identifier.
	 * 
	 * @param nickname
	 *            The nickname of the player.
	 */
	public Player(String nickname) {
		this.nickname = nickname;
	}

	/**
	 * Adds a card to this player's hand.
	 * 
	 * @param card The card to add.
	 */
	public void addCard(Card card) {
		this.cards.add(card);
	}
	
	/**
	 * Removes a card from this player's hand.
	 * 
	 * @param card The card to remove.
	 */
	public void removeCard(Card card) {
		this.cards.remove(card);
	}

	@Override
	public String toString() {
		return "Player [nickname=" + nickname + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((nickname == null) ? 0 : nickname.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Player other = (Player) obj;
		if (nickname == null) {
			if (other.nickname != null) {
				return false;
			}
		} else if (!nickname.equals(other.nickname)) {
			return false;
		}
		return true;
	}
}
